package com.itheima.demo;

import java.io.*;
import java.net.Socket;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/7/16 19:12
 */
public class ClientDemo {
    public static void main(String[] args) throws IOException {
        //创建服务器对象;
        Socket socket = new Socket("127.0.0.1",9999);

        //创建输入流读取本地数据;
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("demo_TCP\\Client\\2019955.jpg"));
        //创建输出流写出文件到服务器;
        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
        //进行读写的操作;
        byte[] bytes = new byte[1024*8];
        int len ;
        while ((len = bis.read(bytes))!=-1){
            bos.write(bytes,0,len);
            bos.flush();
        }
        //告知服务器上传完成;
        socket.shutdownOutput();

        //读取服务器传过来的结果;
        //创建字符输入流;
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        //进行读写;
        String line ;
        while ((line = br.readLine())!= null){
            System.out.println(line);
        }
        //关流;
        bis.close();
        socket.close();
    }
}
